<?php
function is_mobile($mobile){
    return preg_match("/^1[3456789]\d{9}$/", $mobile);
}
function ajaxReturn($array){
    $content=json_encode($array);
    if(empty($_GET['callback'])){
        echo $content;exit;
    }else{
        echo $_GET['callback']."(".$content.")";exit;
    }
}
/**
 * 缓存
 * @param $key 缓存名
 * @param $value 缓存值 为空时为 读,不为空为写
 */
function filecache($key,$value=''){
    if(is_array($key))$key=md5(json_encode($key));
    $filename='cache/'.$key.'.c';clearcache();
    if(empty($value)){
        $res=@file_get_contents($filename);return json_decode($res,true);
    }else{
        if(!is_array($value))$value=array($value);
        $value=json_encode($value);
        file_put_contents($filename,$value);
    }return $filename;
}
//清空所有缓存
function clearcache(){
   $cachepath="cache/";
   $date=date('Y-m-d-h');$cachename='cachetime'.$date.'.c';
   if(file_exists($cachepath.$cachename))return false;
   foreach(scandir($cachepath) as $fn) {
	if(strpos($fn,'.c')>0)unlink($cachepath.$fn);
   }file_put_contents($cachepath.$cachename,'1');
   return true;
}
?>